package io.renren.modules.region.controller;

 

import java.util.Arrays;
import java.util.List;
import java.util.Map;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import io.renren.modules.region.entity.V9RegionEntity;
import io.renren.modules.region.service.V9RegionService;
import io.renren.common.utils.PageUtils;
import io.renren.common.utils.R;



/**
 * 
 *
 * @author chenshun
 * @email sunlightcs@gmail.com
 * @date 2019-09-26 15:04:06
 */
@RestController
@RequestMapping("region/v9region")
public class V9RegionController {
    @Autowired
    private V9RegionService v9RegionService;

    /**
     * 列表
     */
    @RequestMapping("/list")
    @RequiresPermissions("region:v9region:list")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = v9RegionService.queryPage(params);

        return R.ok().put("page", page);
    }
    @RequestMapping("/listAll")
    public R listAll(){
    	List<V9RegionEntity> list = v9RegionService.list();
    	String[] countris=new String[list.size()];
    	for (int i = 0; i < list.size(); i++) {
    		String regionName = list.get(i).getRegionName();
			countris[i]=regionName;
		}
    	 
    	return R.ok().put("list", countris).put("listall", list);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{regionId}")
    @RequiresPermissions("region:v9region:info")
    public R info(@PathVariable("regionId") Integer regionId){
		V9RegionEntity v9Region = v9RegionService.getById(regionId);

        return R.ok().put("v9Region", v9Region);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    @RequiresPermissions("region:v9region:save")
    public R save(@RequestBody V9RegionEntity v9Region){
		v9RegionService.save(v9Region);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    @RequiresPermissions("region:v9region:update")
    public R update(@RequestBody V9RegionEntity v9Region){
		v9RegionService.updateById(v9Region);

        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    @RequiresPermissions("region:v9region:delete")
    public R delete(@RequestBody Integer[] regionIds){
		v9RegionService.removeByIds(Arrays.asList(regionIds));

        return R.ok();
    }

}